package net.sxnic.item.duiying.action;

import net.sxinfo.core.dao.Page;
import net.sxinfo.core.dao.hibernate3.HibernateCriteria;
import net.sxinfo.core.dao.hibernate3.HibernateDaoUtils;
import net.sxinfo.core.dao.hibernate3.HibernateOrder;
import net.sxinfo.core.util.WebUtils;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

@SuppressWarnings("serial")
public class Browse extends DuiyingAction {
	
	private String cyear;
	
	private String cate1;
	
	private Page datas;

	public String execute() throws Exception {

		int page = WebUtils.getPageNumber(request);
		int pageSize = WebUtils.getPageSize(request);

		HibernateOrder order = HibernateDaoUtils.createHibernateOrder(
				"cyear", false);

		HibernateCriteria hc = new HibernateCriteria().add(order);
		
		order = HibernateDaoUtils.createHibernateOrder(
				"cate1", false);
		hc = hc.add(order);
		Criterion dc = null;

		if(StringUtils.isNotBlank(cyear)){
			dc = Restrictions.eq("cyear", cyear);
			hc.add(dc);
		}

		if(StringUtils.isNotBlank(cate1)){
			dc = Restrictions.eq("cate1", cate1);
			hc.add(dc);
		}

		datas = dyManager.getPageByCriteria(page, pageSize, hc);

		return SUCCESS;
	}

	public Page getDatas() {
		return datas;
	}

	public void setDatas(Page datas) {
		this.datas = datas;
	}

	public String getCyear() {
		return cyear;
	}

	public void setCyear(String cyear) {
		this.cyear = cyear;
	}

	public String getCate1() {
		return cate1;
	}

	public void setCate1(String cate1) {
		this.cate1 = cate1;
	}

}
